<?php
apf_require_class('Dao_DAO');

class Dao_Hr_User extends DAO{
    public function get_table_name(){
        return 'user';
    }

    public function get_read_pdo_name(){
        return 'hroa_slave';
    }

    public function get_write_pdo_name(){
        return 'hroa_master';
    }

    public function get_table_pk(){
        return 'user_id';
    }
    /**
     * 获取最大编号的用户
     * @param $user_type_array 用户类型数组
     * @return user_code string
     */
    public function get_user_max_code($user_type_array,$only_get=true){
        $reg = '';
        if($user_type_array == 'S' || $user_type_array == 'P'){
            $reg = strtolower($user_type_array);
        }else{
            $reg = 'o';
        }
        $sql = "SELECT * FROM user_code";
        $res = $this->find_by_sql($sql);
        if(empty($res)){
            return 0;
        }
        if($reg == 'p'){//2013-01-08
            $reg = 'o';
        }
        $next_code_num = intval($res[0][$reg])+1;
        if(!$only_get){
            $sql = "UPDATE user_code SET {$reg}={$next_code_num}";
            $this->execute($sql);
        }
        return $next_code_num;
    }
}